package com.lenovo.agricultureclient.ui.dialog;

import android.app.Activity;
import android.graphics.Color;
import android.view.View;

import com.lenovo.agricultureclient.ClientApp;
import com.lenovo.agricultureclient.R;
/**
 * 设置CO2浓度阀值的对话框
 * @author zongbingwu
 *
 */
public class SettingCo2Dialog extends SettingBaseDialog 
{
	public SettingCo2Dialog(Activity act, ClientApp app) {
		super(act, app);
	}

	@Override
	protected void onInitView() {
		super.onInitView();
		mTitleTextView.setText(R.string.co2_threshold_value_setting);
		//初始化CO2相关控件
		mMajorValueTitleTV.setText(R.string.co2_current_value);
		mMajorStatusTitleTV.setText(R.string.co2_current_status);
		mMajorMinET.setText(mSensorConfig.minCo2+"");
		mMajorMaxET.setText(mSensorConfig.maxCo2+"");
		//第二部分控件设置不可见
		mSlaveLayout.setVisibility(View.GONE);
	}

	@Override
	protected void onUpateView() {
		super.onUpateView();
		int value = mSensorValue.getCo2();
		int min = mSensorConfig.minCo2;
		int max = mSensorConfig.maxCo2;
		//刷新CO2浓度相关控件
		mMajorValueTV.setText(value+"");
		if(value<max && value>min){
			mMajorStatusTV.setText(R.string.normal);
			mMajorStatusTV.setTextColor(Color.BLACK);
		} else {
			mMajorStatusTV.setText(R.string.exception);
			mMajorStatusTV.setTextColor(Color.RED);
		}
	}

	//向服务器端发送设置CO2浓度阀值的请求
	@Override
	protected boolean onPostSet(int majorMin, int majorMax, int slaveMin,int slaveMax) {
		mRequest.resetRequest();
		mRequest.setCo2(majorMin, majorMax);
		startRequest(mRequest);
		return true;
	}
}
